import 'package:flutter/material.dart';

class CheckBoxPage extends StatefulWidget {
  CheckBoxPage({Key key}) : super(key: key);

  @override
  _CheckBoxPageState createState() => _CheckBoxPageState();
}

class _CheckBoxPageState extends State<CheckBoxPage> {

  var flag = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('复选框演示页面'), 
      ), 
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Row(
            children: <Widget>[
              Checkbox(
                value: this.flag, 
                activeColor: Colors.red,
                onChanged: (value) {
                  setState(() {
                    this.flag = value;
                  });
                }
              )
            ],
          ),
          Row(
            children: <Widget>[
              Text(this.flag?'选中':'未选中')
            ]
          ),
          SizedBox(height:40),
          CheckboxListTile(
            value: this.flag, 
            onChanged: (value){
              setState(() {
                this.flag = value;
              });
            },
            title: Text('标题'),
            subtitle: Text('这是一个二级标题')
          ),
          Divider(),
          CheckboxListTile(
            value: this.flag, 
            onChanged: (value){
              setState(() {
                this.flag = value;
              });
            },
            title: Text('标题'),
            subtitle: Text('这是一个二级标题'),
            secondary: Icon(Icons.help),
            selected: this.flag,
          )

        ],
      ),
    );
  }
}